namespace Launcher.View.Model

import System

import Launcher
import Launcher.Model

callable PageChangedEventHandler(sender as object, page as LauncherViewPage)

class LauncherModel:
"""Description of LauncherModel"""

	_actualPage as int
	_paginator = Paginator()

	public static final NumberOfLines 	= 3
	public static final StartCount		= 6

#region events

	event PageChanged as PageChangedEventHandler
	
	protected virtual def OnPageChanged(page as LauncherViewPage):
		PageChanged(self, page)

#endregion

	[getter(Pages)]
	_pages = []
	
	SelectedPage as LauncherViewPage:
		get:
			return _pages[_actualPage]
	
	def constructor():
		pass
		
	def Update(data as List):
		Paginate(data)
		OnPageChanged(SelectedPage)

	private def Paginate(data as List):
		_paginator.Applications = data
		_pages = _paginator.Paginate(StartCount, NumberOfLines)
		_actualPage = 0

#region page navigation

	def Next():
		if IsLast(): return false
		_actualPage++
		OnPageChanged(SelectedPage)
		return true
		
	def Back():
		if IsFirst(): return false
		_actualPage--
		OnPageChanged(SelectedPage)
		return true
	
	def IsFirst():
		return _actualPage == 0
	
	def IsLast():
		return _actualPage >= len(_pages) - 1

#endregion
